﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Miris.HumanMilkAnalyser.DataModel;

namespace Miris.HumanMilkAnalyser.Service.Validation
{
    public class AnalysisItemValidator : DataValidatorBase<AnalysisItem>
    {
        public const string ItemUsageErrorKey = "ItemUsage";
        public const string DietaryRecommendationErrorKey = "DietaryRecommendation";

        /// <summary>
        /// Validate the provided entity. Then check the IsValid property to see the result.
        /// </summary>
        /// <param name="entity">The provided entity to be validated.</param>
        public override void Validate(AnalysisItem entity)
        {
            CheckRequiredItemUsage(entity);
            CheckRequiredDietaryRecommendation(entity);
        }

        /// <summary>
        /// Check if the required ItemUsage is provided.
        /// </summary>
        /// <param name="entity">The instance of AnalysisItem.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckRequiredItemUsage(AnalysisItem entity)
        {
            // Instead of using ValidationHelper.RuleCheckRequiredContent, this accpets space.
            if (string.IsNullOrEmpty(entity.ItemUsage))
            {
                AddError(ItemUsageErrorKey, "指标作用不能为空");
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// Check if the required DietaryRecommendation is provided.
        /// </summary>
        /// <param name="entity">The instance of AnalysisItem.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckRequiredDietaryRecommendation(AnalysisItem entity)
        {
            // Instead of using ValidationHelper.RuleCheckRequiredContent, this accpets space.
            if (string.IsNullOrEmpty(entity.DietaryRecommendation))
            {
                AddError(DietaryRecommendationErrorKey, "饮食建议不能为空");
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
